package com.ruoyi.project.product.styleView.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.product.lineManage.domain.LineManage;
import com.ruoyi.project.product.styleView.domain.StyleView;
import com.ruoyi.project.product.styleView.mapper.StyleViewMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StyleViewServiceImpl implements StyleViewService {
    //声明mapper层属性
    @Autowired
    private StyleViewMapper styleViewMapper;
    @Override
    public List<StyleView> selectStyleViewList(StyleView styleView) {
        return styleViewMapper.selectStyleViewListMapper(styleView);
    }

    /**
     * 校验名称
     * @param styleView
     * @return
     */
    @Override
    public String checkStyleViewNameUnique(StyleView styleView) {
        Long styleId = StringUtils.isNull(styleView.getStyleId()) ? -1L : styleView.getStyleId();
        StyleView info = styleViewMapper.checkStyleViewNameUnique(styleView.getStyleName());
        if (StringUtils.isNotNull(info) && info.getStyleId().longValue() != styleId.longValue())
        {
            return UserConstants.STYLE_NAME_NOT_UNIQUE;
        }
        return UserConstants.STYLE_NAME_UNIQUE;
    }

    /**
     * 新增产品风格
     * @param styleView
     * @return
     */
    @Override
    public int insertStyleView(StyleView styleView) {
        return styleViewMapper.insertStyleView(styleView);
    }

    /**
     * 获取要修改的产品风格信息
     * @param styleId
     * @return
     */
    @Override
    public StyleView selectStyleViewById(Long styleId) {
        return styleViewMapper.selectStyleViewByIdMapper(styleId);
    }

    /**
     * 保存产品风格修改
     * @param styleView
     * @return
     */
    @Override
    public int updateStyleView(StyleView styleView) {
        return styleViewMapper.updateStyleViewMapper(styleView);
    }

    /**
     * 删除产品风格
     * @param ids
     * @return
     */
    @Override
    public int deleteStyleViewByIds(String ids) {
        Long[] styleViewIds = Convert.toLongArray(ids);
        return styleViewMapper.deleteStyleViewByIds(styleViewIds);
    }
}
